#!/usr/bin  python
# _*_ coding:utf-8 _*_
"""
----------------------------------
    File Name: span_tree
    Description:
        Author: lhw
        Date: 2020/6/3
-----------------------------------
"""
"""

"""
from EducationContent import models


def span_tree(data):
    list = []
    tree = {}
    for item in data:
        tree[item['cid']] = item
    for i in data:
        if i["parent_id"] == "root":
            list.append(tree[i['cid']])
        else:
            parent_id = i['parent_id']
            if 'children' not in tree[parent_id]:
                tree[parent_id]["children"] = []
            tree[parent_id]['children'].append(tree[i['cid']])
    for single_data in list:
        if 'children' not in single_data:
            single_data["children"] = []
    return list
